home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / text / hyper / ADtoHT2_1.lha / Source.lha / MyLib.lha / string / strncpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-05  |  605 b   |  50 lines

  1. #include <string.h>
  2.  
  3. /************************************************************************/
  4.  
  5. #undef strncpy
  6.  
  7. #if defined(__GNUC__) && defined(mc68000)
  8.  
  9. asm("
  10.     .globl    _strncpy
  11. _strncpy:
  12.     moveml    sp@(4:W),d0/a0
  13.     movel    d0,a1
  14.     movel    sp@(12:W),d1
  15. L4:    subql    #1,d1
  16.     bcs    L1
  17.     moveb    a0@+,a1@+
  18.     bne    L4
  19.     jra    L2
  20. L3:    clrb    a1@+
  21. L2:    subql    #1,d1
  22.     bcc    L3
  23. L1:    rts
  24. ");
  25.  
  26. #else
  27.  
  28. char *strncpy(char *s1, const char *s2, size_t n)
  29.  
  30. {
  31.   if (n != 0)
  32.     {
  33.       char *s=s1;
  34.  
  35.       while ((*s++=*s2++) && (--n != 0))
  36.     ;
  37.       if (n != 0)
  38.     {
  39.       do
  40.         {
  41.           *s++=0;
  42.         }
  43.       while (--n != 0);
  44.     }
  45.     }
  46.   return s1;
  47. }
  48.  
  49. #endif
  50.